<!DOCTYPE html>
<html>
<head>
    <title>角色编辑</title>
    {% include 'system/common/header.html' %}</head>
<body>
<form class="layui-form" action="">
    <div class="mainBox">
        <div class="main-container">
            <div class="main-container">
              <div class="layui-form-item layui-hide">
                  <label class="layui-form-label">编号</label>
                  <div class="layui-input-block">
                      <input type="text" value="{{ category.id }}" name="categoryId" lay-verify="title"
                             class="layui-input">
                  </div>
              </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">资源名称</label>
                    <div class="layui-input-block">
                        <input type="text" value="{{ category.name }}" name="categoryName" lay-verify="title"
                               autocomplete="off" placeholder="请输入资源名称" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                  <label class="layui-form-label">状态</label>
                  <div class="layui-input-block">
                    <input type="radio" name="isDel" value="0" title="正常">
                    <input type="radio" name="isDel" value="1" title="删除">
                  </div>
                </div>
              </div>                
            </div>
        </div>
    </div>
    <div class="bottom">
        <div class="button-container">
            <button type="submit" class="pear-btn pear-btn-primary pear-btn-sm" lay-submit=""
                    lay-filter="category-update">
                <i class="layui-icon layui-icon-ok"></i>
                提交
            </button>
            <button type="reset" class="pear-btn pear-btn-sm">
                <i class="layui-icon layui-icon-refresh"></i>
                重置
            </button>
        </div>
    </div>
</form>
{% include 'system/common/footer.html' %}
<script>
  layui.use(['form', 'jquery'], function () {
    let form = layui.form
    let $ = layui.jquery

    $("[name=isDel]").each(function () {
      if({{ category.is_del }}==0){
          type="0";
      }else{
          type="1"
      }
      // 根据值回显
      if ($(this).val() == type) {
          $(this).attr("checked", "checked");
          return false;
      }
    })
    form.render(); //更新全部

    form.on('submit(category-update)', function (data) {
      $.ajax({
        url: '/blog/category/update',
        data: JSON.stringify(data.field),
        dataType: 'json',
        contentType: 'application/json',
        type: 'put',
        success: function (result) {
          if (result.success) {
            layer.msg(result.msg, { icon: 1, time: 1000 }, function () {
              parent.layer.close(parent.layer.getFrameIndex(window.name))//关闭当前页
              parent.layui.table.reload('role-table')
            })
          } else {
            layer.msg(result.msg, { icon: 2, time: 1000 })
          }
        }
      })
      return false
    })
  })
</script>
<script>
</script>
</body>
</html>